package ar.com.coonocer.joy.mdg.templatehelpers;

import java.util.List;

import ar.com.coonocer.joy.mdg.xmi.datatype.Multiplicity;
import ar.com.coonocer.joy.mdg.xmi.datatype.MultiplicityRange;

public class MultiplicityUtil {
	public static Integer getLower(Multiplicity multiplicity) {
		if (multiplicity != null) {
			List<MultiplicityRange> range = multiplicity.getRange();
			if (range != null && range.size() != 0) {
				MultiplicityRange multiplicityRange = range.get(0);
				if (multiplicityRange != null) {
					return multiplicityRange.getLower();
				}
			}
		}
		return null;
	}

	// Si es -1, n o * retorna *
	public static String getUpper(Multiplicity multiplicity) {
		if (multiplicity != null) {
			List<MultiplicityRange> range = multiplicity.getRange();
			if (range != null && range.size() != 0) {
				MultiplicityRange multiplicityRange = range.get(0);
				if (multiplicityRange != null) {
					String aux = "*";
					try {
						int i = Integer.valueOf(multiplicityRange.getUpper());
						if (i >= 0) {
							aux = "" + i;
						}
					} catch (Exception e) {
					}
					return aux;
				}
			}
		}
		return null;
	}

}
